package zb.blog.base.util.qiniu.test;

import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.util.Auth;
import org.junit.jupiter.api.Test;
import zb.blog.base.global.GlobalVar;

import java.io.UnsupportedEncodingException;

/**
 * @Author: BinZhang
 * @Date: 2018/5/28 12:19
 * @Description:删除文件演示
 */
public class Delete {
    @Test
    public void test() throws UnsupportedEncodingException {

        Auth auth = Auth.create(GlobalVar.QNY_ACCESS_KEY, GlobalVar.QNY_SECRET_KEY);

        Zone z = Zone.zone0();
        Configuration c = new Configuration(z);

        //实例化一个BucketManager对象
        BucketManager bucketManager = new BucketManager(auth, c);

        try {
            //调用delete方法移动文件
            String bucket = "user";
            String key = "zip/bootstrap.zip";
            Response response = bucketManager.delete(bucket, key);
            System.out.println(response);
        } catch (QiniuException e) {
            //捕获异常信息
            Response r = e.response;
            System.out.println(r.toString());
        }
    }
}
